/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CustomerEntryForm.java
 *
 * Created on Sep 5, 2011, 1:49:36 PM
 */
package svp;
import java.awt.Color;
import java.awt.Cursor;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdesktop.application.Task;
import svp.SVPApp;
import svp.SVPView;
import javax.swing.JTextField;
import java.sql.*;
import java.util.*;
import javax.persistence.EntityTransaction;
import javax.swing.JFrame;
import javax.xml.ws.Action;
import svp.exceptions.NonexistentEntityException;
/**
 *
 * @author kandamaran
 */
public class CustomerEntryForm extends javax.swing.JDialog {

    /** Creates new form CustomerEntryForm */
    public CustomerEntryForm(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(svp.SVPApp.class).getContext().getResourceMap(CustomerEntryForm.class);
        SVPPUEntityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory(resourceMap.getString("SVPPUEntityManager.persistenceUnit")).createEntityManager(); // NOI18N
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        customerAddrTA = new javax.swing.JTextArea();
        stateCB = new javax.swing.JComboBox();
        postalCodeTF = new javax.swing.JTextField();
        officePhNoTF = new javax.swing.JTextField();
        mobilePhNo1TF = new javax.swing.JTextField();
        mobilePhNo2TF = new javax.swing.JTextField();
        customerMessageTF = new javax.swing.JTextField();
        customerSaveBT = new javax.swing.JButton();
        cancelCustomerEntryFormBT = new javax.swing.JButton();
        CustomerNameCB = new javax.swing.JComboBox();
        customerPhNOCB = new javax.swing.JComboBox();
        cityCB = new javax.swing.JComboBox();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        statusLB = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setLocationByPlatform(true);
        setName("Form"); // NOI18N
        setResizable(false);
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                formComponentShown(evt);
            }
        });

        jPanel1.setName("jPanel1"); // NOI18N

        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setFont(resourceMap.getFont("jLabel2.font")); // NOI18N
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setFont(resourceMap.getFont("jLabel3.font")); // NOI18N
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setFont(resourceMap.getFont("jLabel4.font")); // NOI18N
        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setFont(resourceMap.getFont("jLabel5.font")); // NOI18N
        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel6.setFont(resourceMap.getFont("jLabel6.font")); // NOI18N
        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jLabel7.setFont(resourceMap.getFont("jLabel7.font")); // NOI18N
        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel8.setFont(resourceMap.getFont("jLabel8.font")); // NOI18N
        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jLabel9.setFont(resourceMap.getFont("jLabel9.font")); // NOI18N
        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jLabel10.setFont(resourceMap.getFont("jLabel10.font")); // NOI18N
        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        jPanel2.setName("jPanel2"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        customerAddrTA.setColumns(20);
        customerAddrTA.setFont(resourceMap.getFont("customerAddrTA.font")); // NOI18N
        customerAddrTA.setLineWrap(true);
        customerAddrTA.setRows(5);
        customerAddrTA.setWrapStyleWord(true);
        customerAddrTA.setName("customerAddrTA"); // NOI18N
        jScrollPane1.setViewportView(customerAddrTA);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 288, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 63, Short.MAX_VALUE)
        );

        stateCB.setEditable(true);
        stateCB.setFont(resourceMap.getFont("stateCB.font")); // NOI18N
        List customerStateList = SVPPUEntityManager.createNamedQuery("CustomerCityState.stateAll").getResultList();
        Collections.sort(customerStateList);
        stateCB.setModel(new javax.swing.DefaultComboBoxModel (customerStateList.toArray()));
        new S17NonStrict(stateCB);
        JTextField customerStateTF = (JTextField)stateCB.getEditor().getEditorComponent();
        customerStateTF.setText("");
        stateCB.setName("stateCB"); // NOI18N
        stateCB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                stateCBActionPerformed(evt);
            }
        });

        postalCodeTF.setFont(resourceMap.getFont("postalCodeTF.font")); // NOI18N
        postalCodeTF.setText(resourceMap.getString("postalCodeTF.text")); // NOI18N
        postalCodeTF.setName("postalCodeTF"); // NOI18N
        postalCodeTF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                postalCodeTFActionPerformed(evt);
            }
        });

        officePhNoTF.setFont(resourceMap.getFont("officePhNoTF.font")); // NOI18N
        officePhNoTF.setText(resourceMap.getString("officePhNoTF.text")); // NOI18N
        officePhNoTF.setName("officePhNoTF"); // NOI18N

        mobilePhNo1TF.setFont(resourceMap.getFont("mobilePhNo1TF.font")); // NOI18N
        mobilePhNo1TF.setText(resourceMap.getString("mobilePhNo1TF.text")); // NOI18N
        mobilePhNo1TF.setName("mobilePhNo1TF"); // NOI18N

        mobilePhNo2TF.setFont(resourceMap.getFont("mobilePhNo2TF.font")); // NOI18N
        mobilePhNo2TF.setText(resourceMap.getString("mobilePhNo2TF.text")); // NOI18N
        mobilePhNo2TF.setName("mobilePhNo2TF"); // NOI18N

        customerMessageTF.setFont(resourceMap.getFont("customerMessageTF.font")); // NOI18N
        customerMessageTF.setText(resourceMap.getString("customerMessageTF.text")); // NOI18N
        customerMessageTF.setName("customerMessageTF"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(svp.SVPApp.class).getContext().getActionMap(CustomerEntryForm.class, this);
        customerSaveBT.setAction(actionMap.get("setNewCustomerInfo")); // NOI18N
        customerSaveBT.setText(resourceMap.getString("customerSaveBT.text")); // NOI18N
        customerSaveBT.setName("customerSaveBT"); // NOI18N
        customerSaveBT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                customerSaveBTActionPerformed(evt);
            }
        });

        cancelCustomerEntryFormBT.setText(resourceMap.getString("cancelCustomerEntryFormBT.text")); // NOI18N
        cancelCustomerEntryFormBT.setName("cancelCustomerEntryFormBT"); // NOI18N
        cancelCustomerEntryFormBT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelCustomerEntryFormBTActionPerformed(evt);
            }
        });

        CustomerNameCB.setEditable(true);
        CustomerNameCB.setFont(resourceMap.getFont("CustomerNameCB.font")); // NOI18N
        List customerNameList = SVPPUEntityManager.createNamedQuery("CustomerTbl.name").getResultList();
        Collections.sort(customerNameList);
        CustomerNameCB.setModel(new javax.swing.DefaultComboBoxModel (customerNameList.toArray()));
        new S17NonStrict(CustomerNameCB);
        JTextField CustomerNameTF = (JTextField)CustomerNameCB.getEditor().getEditorComponent();
        CustomerNameTF.setText("");
        CustomerNameCB.setName("CustomerNameCB"); // NOI18N
        CustomerNameCB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CustomerNameCBActionPerformed(evt);
            }
        });

        customerPhNOCB.setEditable(true);
        customerPhNOCB.setFont(resourceMap.getFont("customerPhNOCB.font")); // NOI18N
        List customerPhList = SVPPUEntityManager.createNamedQuery("CustomerTbl.MasterPhNo").getResultList();
        Collections.sort(customerPhList);
        customerPhNOCB.setModel(new javax.swing.DefaultComboBoxModel (customerPhList.toArray()));
        new S17NonStrict(customerPhNOCB);
        JTextField customerPhNOTF = (JTextField)customerPhNOCB.getEditor().getEditorComponent();
        customerPhNOTF.setText("");
        customerPhNOCB.setName("customerPhNOCB"); // NOI18N
        customerPhNOCB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                customerPhNOCBActionPerformed(evt);
            }
        });

        cityCB.setEditable(true);
        cityCB.setFont(resourceMap.getFont("cityCB.font")); // NOI18N
        List customerCityList = SVPPUEntityManager.createNamedQuery("CustomerCityState.cityAll").getResultList();
        Collections.sort(customerCityList);
        cityCB.setModel(new javax.swing.DefaultComboBoxModel (customerCityList.toArray()));
        new S17NonStrict(cityCB);
        JTextField customerCityTF = (JTextField)cityCB.getEditor().getEditorComponent();
        customerCityTF.setText("");
        cityCB.setName("cityCB"); // NOI18N
        cityCB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cityCBActionPerformed(evt);
            }
        });

        jLabel12.setFont(resourceMap.getFont("jLabel12.font")); // NOI18N
        jLabel12.setForeground(resourceMap.getColor("jLabel12.foreground")); // NOI18N
        jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N
        jLabel12.setName("jLabel12"); // NOI18N

        jLabel13.setFont(resourceMap.getFont("jLabel13.font")); // NOI18N
        jLabel13.setForeground(resourceMap.getColor("jLabel13.foreground")); // NOI18N
        jLabel13.setText(resourceMap.getString("jLabel13.text")); // NOI18N
        jLabel13.setName("jLabel13"); // NOI18N

        jLabel14.setFont(resourceMap.getFont("jLabel14.font")); // NOI18N
        jLabel14.setForeground(resourceMap.getColor("jLabel14.foreground")); // NOI18N
        jLabel14.setText(resourceMap.getString("jLabel14.text")); // NOI18N
        jLabel14.setName("jLabel14"); // NOI18N

        jLabel15.setFont(resourceMap.getFont("jLabel15.font")); // NOI18N
        jLabel15.setForeground(resourceMap.getColor("jLabel15.foreground")); // NOI18N
        jLabel15.setText(resourceMap.getString("jLabel15.text")); // NOI18N
        jLabel15.setName("jLabel15"); // NOI18N

        jLabel16.setFont(resourceMap.getFont("jLabel16.font")); // NOI18N
        jLabel16.setForeground(resourceMap.getColor("jLabel16.foreground")); // NOI18N
        jLabel16.setText(resourceMap.getString("jLabel16.text")); // NOI18N
        jLabel16.setName("jLabel16"); // NOI18N

        jLabel17.setFont(resourceMap.getFont("jLabel17.font")); // NOI18N
        jLabel17.setForeground(resourceMap.getColor("jLabel17.foreground")); // NOI18N
        jLabel17.setText(resourceMap.getString("jLabel17.text")); // NOI18N
        jLabel17.setName("jLabel17"); // NOI18N

        jLabel18.setFont(resourceMap.getFont("jLabel18.font")); // NOI18N
        jLabel18.setForeground(resourceMap.getColor("jLabel18.foreground")); // NOI18N
        jLabel18.setText(resourceMap.getString("jLabel18.text")); // NOI18N
        jLabel18.setName("jLabel18"); // NOI18N

        jLabel19.setText(resourceMap.getString("jLabel19.text")); // NOI18N
        jLabel19.setName("jLabel19"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel10)
                            .addComponent(jLabel9)
                            .addComponent(jLabel8)
                            .addComponent(jLabel7)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(customerMessageTF, javax.swing.GroupLayout.PREFERRED_SIZE, 330, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(mobilePhNo2TF, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(mobilePhNo1TF, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(officePhNoTF, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 224, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(customerPhNOCB, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(CustomerNameCB, javax.swing.GroupLayout.Alignment.LEADING, 0, 231, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(cityCB, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(postalCodeTF, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 153, Short.MAX_VALUE)
                                    .addComponent(stateCB, 0, 153, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel16, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel17, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(159, 159, 159))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(209, 209, 209)
                        .addComponent(customerSaveBT, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(cancelCustomerEntryFormBT)
                        .addGap(68, 68, 68)
                        .addComponent(jLabel18, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel19, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(59, 59, 59))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(32, 32, 32)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(CustomerNameCB, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(customerPhNOCB, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addComponent(jLabel12)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel13)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel4)
                                    .addComponent(cityCB, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(stateCB, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel5))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(postalCodeTF, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel6)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel15)
                                .addGap(20, 20, 20)
                                .addComponent(jLabel16)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel17)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(officePhNoTF, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(mobilePhNo1TF, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9)
                            .addComponent(mobilePhNo2TF, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jLabel14))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(customerMessageTF, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(36, 36, 36)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(customerSaveBT)
                            .addComponent(cancelCustomerEntryFormBT))
                        .addContainerGap(22, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel19)
                            .addComponent(jLabel18, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap())))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel3.setFont(resourceMap.getFont("jPanel3.font")); // NOI18N
        jPanel3.setName("jPanel3"); // NOI18N

        jLabel11.setFont(resourceMap.getFont("jLabel11.font")); // NOI18N
        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        statusLB.setFont(resourceMap.getFont("statusLB.font")); // NOI18N
        statusLB.setText(resourceMap.getString("statusLB.text")); // NOI18N
        statusLB.setName("statusLB"); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jLabel11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusLB)
                .addContainerGap(251, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel11)
                .addComponent(statusLB))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 605, Short.MAX_VALUE)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(0, 0, 0)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents


    public void refreshCustomerNameCB(){
    // jComboBox1.addItem(customerName);
     List<String> customerNameList = SVPPUEntityManager.createNamedQuery("CustomerTbl.name").getResultList();
    // customerNameList.add(customerName);
    Collections.sort(customerNameList);
//    for(String l: customerNameList){
//        System.out.println(l);
//    }
    CustomerNameCB.setModel(new javax.swing.DefaultComboBoxModel (customerNameList.toArray()));
//    for(int i=0;i<CustomerNameCB.getItemCount();i++)
//    System.out.println(i + " Item 1 : " + CustomerNameCB.getItemAt(i));
    
    new S17NonStrict(CustomerNameCB);
    JTextField field = (JTextField)CustomerNameCB.getEditor().getEditorComponent();
    field.setText("");

//    System.out.println("Updated customer name combo box......");
   }
   
 
private void cancelCustomerEntryFormBTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelCustomerEntryFormBTActionPerformed
// TODO add your handling code here:
  CustomerNameCB.getEditor().setItem("");
  customerPhNOCB.getEditor().setItem("");
  customerAddrTA.setText("");
  cityCB.getEditor().setItem("");
  stateCB.getEditor().setItem("");
  postalCodeTF.setText("");
  mobilePhNo1TF.setText("");
  mobilePhNo2TF.setText("");
  officePhNoTF.setText("");
  customerMessageTF.setText("");
  statusLB.setForeground(Color.black);
  statusLB.setText("Add New Customer and Edit Existing Customer.");
   this.dispose();
}//GEN-LAST:event_cancelCustomerEntryFormBTActionPerformed

private void customerSaveBTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_customerSaveBTActionPerformed
// TODO add your handling code here:
  
//  if(CustomerNameCB.getEditor().getItem().toString().equalsIgnoreCase("")==false && customerPhNOCB.getEditor().getItem().toString().equalsIgnoreCase("")==false 
//              &&customerAddrTA.getText().trim().equalsIgnoreCase("")==false && cityCB.getEditor().getItem().toString().equalsIgnoreCase("")==false
//              && stateCB.getEditor().getItem().toString().equalsIgnoreCase("")==false && postalCodeTF.getText().trim().equalsIgnoreCase("")==false){
//      if()
//         this.dispose(); 
//      
//      }
//      else{
//          statusLB.setForeground(Color.red);
//          statusLB.setText("Details cannot be Empty..!!");
//   
//      }
    
}//GEN-LAST:event_customerSaveBTActionPerformed

    private void CustomerNameCBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CustomerNameCBActionPerformed
        // TODO add your handling code here:
        if(statusLB.getForeground() != Color.black){
        statusLB.setForeground(Color.black);
        statusLB.setText("Add New Customer and Edit Existing Customer.");
        }
    }//GEN-LAST:event_CustomerNameCBActionPerformed

    private void customerPhNOCBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_customerPhNOCBActionPerformed
        // TODO add your handling code here:
        if(statusLB.getForeground() != Color.black){
        statusLB.setForeground(Color.black);
        statusLB.setText("Add New Customer and Edit Existing Customer.");
        }
    }//GEN-LAST:event_customerPhNOCBActionPerformed

    private void cityCBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cityCBActionPerformed
        // TODO add your handling code here:
        if(statusLB.getForeground() != Color.black){
        statusLB.setForeground(Color.black);
        statusLB.setText("Add New Customer and Edit Existing Customer.");
        }
    }//GEN-LAST:event_cityCBActionPerformed

    private void stateCBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stateCBActionPerformed
        // TODO add your handling code here:
        if(statusLB.getForeground() != Color.black){
        statusLB.setForeground(Color.black);
        statusLB.setText("Add New Customer and Edit Existing Customer.");
        }
    }//GEN-LAST:event_stateCBActionPerformed

    private void postalCodeTFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_postalCodeTFActionPerformed
        // TODO add your handling code here:
        if(statusLB.getForeground() != Color.black){
        statusLB.setForeground(Color.black);
        statusLB.setText("Add New Customer and Edit Existing Customer.");
        }
    }//GEN-LAST:event_postalCodeTFActionPerformed

    private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
        // TODO add your handling code here:
        this.refreshCustomerNameCB();
  CustomerNameCB.getEditor().setItem("");
  customerPhNOCB.getEditor().setItem("");
  customerAddrTA.setText("");
  cityCB.getEditor().setItem("");
  stateCB.getEditor().setItem("");
  postalCodeTF.setText("");
  mobilePhNo1TF.setText("");
  mobilePhNo2TF.setText("");
  officePhNoTF.setText("");
  customerMessageTF.setText("");
  statusLB.setForeground(Color.black);
  statusLB.setText("Add New Customer and Edit Existing Customer.");
    }//GEN-LAST:event_formComponentShown

    /**
     * @param args the command line arguments
     */
    public void customerEntryForm() {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    //javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(CustomerEntryForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(CustomerEntryForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(CustomerEntryForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(CustomerEntryForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                final CustomerEntryForm dialog = new CustomerEntryForm(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        dialog.dispose();
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                @org.jdesktop.application.Action(block = Task.BlockingScope.APPLICATION)
    public Task setNewCustomerInfo() {
        return new SetNewCustomerInfoTask(org.jdesktop.application.Application.getInstance(svp.SVPApp.class));
    }

    private class SetNewCustomerInfoTask extends org.jdesktop.application.Task<Object, Void> {
         CustomerTblJpaController cdb = new CustomerTblJpaController(SVPPUEntityManager.getEntityManagerFactory());
      CustomerTblPK customer1 = new CustomerTblPK();
      CustomerTbl customer = new CustomerTbl(customer1);
        SetNewCustomerInfoTask(org.jdesktop.application.Application app) {
            // Runs on the EDT.  Copy GUI state that
            // doInBackground() depends on from parameters
            // to SetNewCustomerInfoTask fields, here.
            super(app);
        }
        @Override protected Object doInBackground() {
            // Your Task's code here.  This method runs
            // on a background thread, so don't reference
            // the Swing GUI from here.
             List customerIdList =  SVPPUEntityManager.createNamedQuery("CustomerTbl.id").getResultList();
             String result = null; 
            
    Collections.sort(customerIdList);
    //Integer customerId = Integer.parseInt(customerIdList.get(customerIdList.size() - 1).toString().trim());
     try {
     //SVPPUEntityManager.getTransaction().begin();
     // CustomerTblJpaController cdb = new CustomerTblJpaController(SVPPUEntityManager.getEntityManagerFactory());
     // CustomerTblPK customer1 = new CustomerTblPK();
      customer1.setCustomerId(String.valueOf(customerIdList.size()));
      customer1.setCustomerName(CustomerNameCB.getEditor().getItem().toString());
     // CustomerTbl customer = new CustomerTbl(customer1);
      customer.setCustomerphoneOff1(customerPhNOCB.getEditor().getItem().toString().trim());
      customer.setCustomerAddress(customerAddrTA.getText().trim());
      customer.setCustomerCity(cityCB.getEditor().getItem().toString());
      customer.setCustomerState(stateCB.getEditor().getItem().toString());
      customer.setCustomerpostalCode(postalCodeTF.getText().trim());
      customer.setCustomermobileNo1(mobilePhNo1TF.getText().trim());
      customer.setCustomermobileNo2(mobilePhNo2TF.getText().trim());
      customer.setCustomerphoneOff2(officePhNoTF.getText().trim());
      customer.setCustomerphoneRes(null);
      customer.setCustomerComment(customerMessageTF.getText().trim());
      if(customer1.getCustomerName().equalsIgnoreCase("")==false && customer.getCustomerAddress().equalsIgnoreCase("")==false 
              && customer.getCustomerCity().equalsIgnoreCase("")==false && customer.getCustomerState().equalsIgnoreCase("")==false
              && customer.getCustomerpostalCode().equalsIgnoreCase("")==false && customer.getCustomerphoneOff1().equalsIgnoreCase("")==false){
      
          cdb.create(customer);
          result = "Success";
      }
      else{
          statusLB.setForeground(Color.red);
          statusLB.setText("Details cannot be Empty..!!");
          result = "DetailsEmpty";
      }
      }catch(Exception e){
       e.printStackTrace();
        // CustomerTblJpaController cdb = new CustomerTblJpaController(SVPPUEntityManager.getEntityManagerFactory());
       statusLB.setForeground(Color.red);
          statusLB.setText("The Customer Name or Phone number is already in our record");
          result = "CustomerExist";     
      }

       
            return result;  // return your result
        }
        @Override protected void succeeded(Object result) {
            // Runs on the EDT.  Update the GUI based on
            // the result computed by doInBackground().
            CustomerEntryForm cef = new CustomerEntryForm(SVPApp.getApplication().getMainFrame(), true);
            if(result.toString().equalsIgnoreCase("Success")){
              cef.setVisible(false);  
              statusLB.setForeground(Color.black);
              statusLB.setText("Add New Customer and Edit Existing Customer.");
              CustomerNameCB.getEditor().setItem("");
              customerPhNOCB.getEditor().setItem("");
              customerAddrTA.setText("");
              cityCB.getEditor().setItem("");
              stateCB.getEditor().setItem("");
              postalCodeTF.setText("");
              mobilePhNo1TF.setText("");
              mobilePhNo2TF.setText("");
              officePhNoTF.setText("");
              customerMessageTF.setText("");
               statusLB.setForeground(Color.GREEN);
                statusLB.setText("Customer information has been successfully added..!!");
            } 
            else if(result.toString().equalsIgnoreCase("DetailsEmpty")){
                statusLB.setForeground(Color.red);
                statusLB.setText("Details cannot be Empty..!!");
            }
            else if(result.toString().equalsIgnoreCase("CustomerExist")){
               statusLB.setForeground(Color.red);
               statusLB.setText("The Customer Name or Phone number already exist in our record");
            }
        }
    }


  
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox CustomerNameCB;
    public javax.persistence.EntityManager SVPPUEntityManager;
    private javax.swing.JButton cancelCustomerEntryFormBT;
    private javax.swing.JComboBox cityCB;
    private javax.swing.JTextArea customerAddrTA;
    private javax.swing.JTextField customerMessageTF;
    private javax.swing.JComboBox customerPhNOCB;
    private javax.swing.JButton customerSaveBT;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField mobilePhNo1TF;
    private javax.swing.JTextField mobilePhNo2TF;
    private javax.swing.JTextField officePhNoTF;
    private javax.swing.JTextField postalCodeTF;
    private javax.swing.JComboBox stateCB;
    private javax.swing.JLabel statusLB;
    // End of variables declaration//GEN-END:variables
}
